class ColorUtil {
  constructor() {

  }

  /**
   * 获取随机颜色
   * @returns {string}
   */
  getRandomColor() {
    return "#" + (function (color) {
      let rand = Math.floor(Math.random() * 0XFFFFFF).toString(16);
      return rand.length === 6 ? rand : color;
    })('');
  }

  /**
   * rgb 转换为 hex
   * @param r
   * @param g
   * @param b
   * @returns {string}
   */
  rgbToHex(r, g, b) {
    // const toHex = num => {
    //   const hex = num.toString(16)
    //   return hex.length === 1 ? `0${hex}` : hex
    // }
    // return `#${toHex(r)}${toHex(g)}${toHex(b)}`

    return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
  }

}

export default new ColorUtil()
